package com.yc.spring.test;

import com.yc.spring.IocConfig;
import com.yc.spring.bean.HelloBean;
import com.yc.spring.ioc.AnnotationConfigApplicationContext;
import com.yc.spring.vote.VoteConfig;
import com.yc.spring.vote.biz.VoteBiz;
import com.yc.spring.vote.dao.VoteDao;
import com.yc.spring.vote.web.VoteAction;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

public class SpringTest3 {
    @Test
    public void test1(){
        AnnotationConfigApplicationContext ctx;
        ctx = new AnnotationConfigApplicationContext(IocConfig.class);
        HelloBean hello = (HelloBean) ctx.getBean("hello");

        HelloBean bean = ctx.getBean(HelloBean.class);
        bean.sayHello();

        hello.sayHello();
    }

    @Test
    public void test2() {
        AnnotationConfigApplicationContext ctx;
        ctx = new AnnotationConfigApplicationContext(VoteConfig.class);

        VoteAction bean = ctx.getBean(VoteAction.class);
        Assert.assertNotNull(bean);
        Assert.assertNotNull(bean.getBiz());
        Assert.assertNotNull(bean.getDao());
        Assert.assertNotNull(bean.getBiz().getVoteDao());
    }
}

